package com.huarun.common.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.huarun.module.airconditioning.bean.UseTime;
import com.huarun.module.airconditioning.bean.UseTimeParse;

/**
 * @author wyq
 * @date 2018年12月14日 上午10:00:01
 * @Description 类描述
 */
public class TimeParse {


	public static Map<String, Object> parse(List<UseTime> useTimeList) {
/*
		List<UseTime> useTimeList = new ArrayList<>();
		for (int i = 1; i <= 6; i++) {
			UseTime time = new UseTime();
			time.setStartDate("2018-12-0" + i);
			time.setEndDate("2018-12-0" + i);
			time.setStartTime("00:00");
			time.setEndTime("10:00");
			useTimeList.add(time);
		}
		for (int i = 1; i <= 6; i++) {
			UseTime time = new UseTime();
			time.setStartDate("2018-12-1" + i);
			time.setEndDate("2018-12-1" + i);
			time.setStartTime("08:00");
			time.setEndTime("10:00");
			useTimeList.add(time);
		}
		for (int i = 1; i <= 6; i++) {
			UseTime time = new UseTime();
			time.setStartDate("2018-12-2" + i);
			time.setEndDate("2018-12-2" + i);
			time.setStartTime("07:00");
			time.setEndTime("09:00");
			useTimeList.add(time);
		}*/
		Map<String, Set<String>> map = test(useTimeList);
		Map<String, Object> result = null;
		Set<String> keys = map.keySet();
		List<String> childSet = null;
		List<Map<String, Object>> list = new ArrayList<>();
		for (String key : keys) {
			result = new HashMap<>();
			Set<String> set = map.get(key);
			String[] a = key.split("#");
			result.put("startTime", a[0]);
			result.put("endTime", a[1]);
			childSet = new ArrayList<>();
			for (String date : set) {
//				String subDate = date.substring(date.length() - 2);
				childSet.add(date);
			}
			Collections.sort(childSet);
			result.put("date", childSet);
			list.add(result);
		}

		Map<String, Object> result1 = new HashMap<>();
		result1.put("UseTimeInfo", list);
		return result1;
	}



	public static Map<String, Set<String>> test(List<UseTime> useTimeList) {
		List<UseTimeParse> list = new ArrayList<>();
		List<UseTime> useTimeList1 = useTimeList;
		Map<String, Set<String>> map = new HashMap<>();
		String key = "";
		Set<String> set = null;
		for (UseTime time : useTimeList) {
			key = time.getStartTime() + "#" + time.getEndTime();
			if (map.get(key) == null) {
				set = new HashSet<>();
				set.add(time.getStartDate());
				map.put(key, set);
			} else {
				map.get(key).add(time.getStartDate());
				map.put(key, map.get(key));
			}

		}
		return map;
	}


}
